package com.migu.contacts.main.my;

import static com.migu.contacts.net.Service.API;

import android.util.Log;
import android.view.View;
import android.widget.CompoundButton;

import com.blankj.utilcode.util.ToastUtils;
import com.frank.libandroid.BaseActivity;
import com.migu.contacts.databinding.ActivitySettingBinding;
import com.migu.contacts.login.LoginActivity;
import com.migu.contacts.main.my.setting.AccountActivity;
import com.migu.contacts.main.my.setting.HelpActivity;
import com.migu.contacts.main.my.setting.ServiceActivity;
import com.migu.contacts.net.ResultCallback;
import com.migu.contacts.util.UserCenter;

public class SettingActivity extends BaseActivity<ActivitySettingBinding> {

    public void logout(View view) {
        UserCenter.logout();
        start(LoginActivity.class);
        finish();
    }

    @Override
    protected void initView() {
        super.initView();
        mBinding.noticeSwitch.setChecked(UserCenter.userBean.messageTip == 1);
        mBinding.noticeSwitch.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
                Log.d(TAG, "onCheckedChanged() called with: buttonView = [" + buttonView + "], isChecked = [" + isChecked + "]");
                int status = isChecked ? 1 : 0;
                API.message_set(status).enqueue(new ResultCallback<Boolean>() {
                    @Override
                    protected void onSuccess(Boolean aBoolean) {
                        ToastUtils.showShort("设置成功");
                    }
                });
            }
        });
    }

    public void help(View view) {
        start(HelpActivity.class);
    }

    public void account(View view) {
        start(AccountActivity.class);
    }

    public void contact(View view) {
        start(ServiceActivity.class);
    }
}